<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../js/jquery-3.4.1.js"></script>
    <link rel="stylesheet" href="../css/index.css"/>
    <link rel="stylesheet" href="../css/singup.css"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>给他(她)留言</title>
</head>
<body>

<div class="text" id="main">
    <img class="imga" src="../img/one.jpg">
    <div class="title_text">
        远方的树
    </div>

        <div class="sigone">
            <input class="input" placeholder="输入她的名字"  id="name">
        </div>
        <div class="sigone">
            <textarea class="input1" placeholder="输入留言内容" name="text" id="text"></textarea>
        </div>

        <div class="sigone">
            <button class="button" onclick="singup()">留言给他(她)</button>
        </div>


    <div href="index.html" class="at" style="margin-top: 200px">
        <a href="index">
            查看留言
        </a>
    </div>


</div>
</body>
<script>
    function singup(){
        const name = $("#name").val();
        const text = $("#text").val();
        if(name === '' || text === ''){
            alert("请输入完整!");
            return false;
        }

        $.ajax({
            url:"singup",
            type:"post",
            ataType:"json",
            data:{name:name,text:text},
            success : function(data) {
                if(data === "true"){
                    alert("留言成功");
                }else {
                    alert("留言失败");
                }
            }
        })

    }
</script>
</html>